package com.google.code.cisx.client.model;

import java.util.ArrayList;
import java.util.List;

public abstract class GadgetClass {

  private String name;

  private boolean refreshable;

  /**
   * Is valid login required for access to this Gadget.
   */
  private boolean secured = true;

  private ArrayList userprefs = new ArrayList();

  private static List classes = new ArrayList();

  public static void addClass(GadgetClass gclass) {
    classes.add(gclass);
  }

  public static List getClasses() {
    return classes;
  }

  public GadgetClass(String n, boolean r) {
    name = n;
    refreshable = r;
  }

  /**
   * @param name Gadget Name
   * @param refreshable <code>true</code> if the Gadget state/view can be
   *          refreshed, else <code>false</code>.
   * @param secured <code>true</code> if accessing/viewing the Gadget requires
   *          a valid system user to be logged in, else <code>false</code>.
   */
  public GadgetClass(String name, boolean refreshable, boolean secured) {
    super();
    this.name = name;
    this.refreshable = refreshable;
    this.secured = secured;
  }

  /**
   * Extensions are expected to implement and provide a way to create an
   * instance of themselves.
   * 
   * @return
   */
  public abstract Gadget newGadget();

  public boolean isRefreshable() {
    return refreshable;
  }

  /**
   * Determines if accessing/viewing the Gadget requires a valid system user to
   * be logged in.
   * 
   * @return <code>true</code> if accessing/viewing the Gadget requires a
   *         valid system user to be logged in, else <code>false</code>.
   */
  public boolean isSecured() {
    return secured;
  }

  public String getName() {
    return name;
  }

  public int getUserPrefsCount() {
    return userprefs.size();
  }

  public UserPref getUserPref(int pos) {
    return (UserPref) userprefs.get(pos);
  }

  protected void addUserPref(UserPref up) {
    userprefs.add(up);
  }
}
